import numpy as np
import os
def label2yoloseg(label_array,h,w):
    obj_num=label_array.shape[0]//4
    out_put_array=np.zeros([obj_num,9])
    for i in range(obj_num):
        out_put_array[i,0]=label_array[i*4,2]
        for j in range(4):
            out_put_array[i,1+j*2:1+j*2+2]=label_array[i*4+j,0:2]/h
    return out_put_array

os.makedirs('train_yoloseg',exist_ok=True)
os.makedirs('val_yoloseg',exist_ok=True)

name1_list=os.listdir('./val')
num=0
for name1 in name1_list:
    num=num+1
    label_array=np.loadtxt('./val/'+name1)
    out_put_array = label2yoloseg(label_array, 1000, 1000)
    np.savetxt('./val_yoloseg/'+name1, out_put_array, fmt="%d %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f")
    print(num)


